// Package main
// @Author zhongxc
// @Date 2023/12/25 10:59:00
// @Desc
package main

import (
	"fmt"
	"sync"
)

var lock = &sync.Mutex{}

type Single struct {
}

var singleInstance *Single

func GetInstance() *Single {
	if singleInstance == nil {
		lock.Lock()
		defer lock.Unlock()
		if singleInstance != nil {
			fmt.Println("single instance already created.")
		} else {
			fmt.Println("creating single instance now.")
			singleInstance = &Single{}
		}
	}
	return singleInstance
}

func main() {
	for i := 0; i < 30; i++ {
		go GetInstance()
	}
	fmt.Println("get instance done.")
}
